{extend name="public/base" /}
{block name="style"}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/libs/bootstrap-editable.css">
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/index.css?v=20221110&times={:time()}"/>
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/iconfont.css"/>
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/tooltipify.css">
</link>
{include file="material/_ali_icon" /}
<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugs/webuploader/webuploader.css">
<style>
    .main-box-body .navs .active {
        background: azure;
        color: #03a9f4;
        border: 1px solid #03a9f4;
        border-radius: 5px;
    }

    a {
        color: #777;
        text-decoration: none;
    }

    a:hover {
        text-decoration: none
    }

    .table tbody > tr > td {
        padding: 3px 8px;
    }

    .table-hover > tbody > tr:nth-child(odd) {
        background-color: #f9f9f9;
    }

    .table-responsive {
        min-height: 470px;
    }
</style>
<style>
    .uploadify-button-text {
        position: relative;
        display: inline-block;
        cursor: pointer;
        background: #fff;
        padding: 0px 5px;
        color: #333;
        text-align: center;
        border-radius: 3px;
        overflow: hidden;
        border: 1px solid #ccc;
    }

    em {
        color: red;
    }
</style>
{/block}
{block name="body"}
<div class="main-box clearfix">
    <header class="main-box-header clearfix">
        <div class="pull-right">
            <button type="button" class="btn btn-warning">
                <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;">
                全选
            </button>
            <!-- <button type="button" class="btn btn-warning"> <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;"> 全选 </button> -->
            <button type="button" class="btn btn-primary" id="createUrl">
                <i class="fa fa-plus"></i> 添加 <span class="caret"></span>
            </button>
            <button class="btn btn-danger ajax-post confirm" url="{:url('del',array('type'=>'twtitle'))}" target-form="ids">删 除
            </button>
        </div>
        <div class="row">
            <form method="get">

                <style>
                    @media (min-width: 1200px) {
                        .col-lg-1 {
                            width: 7.5%;
                        }
                    }
                </style>
                {include file="material/_date" /}
                <div class="col-sm-12 col-md-4 col-lg-2">
                    <input type="text" class="form-control" name="keyword" value="" placeholder="请输入关键字搜索">
                </div>

                <div class="col-sm-12 col-md-1" style="width: 59px;">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </div>
                {if(!empty($userlist))}
                <div class="col-sm-12 col-lg-1">
                    <select name="userid" id="userid" class="form-control">
                        <option value="99999">全部工号</option>
                        {foreach name="userlist" item="vo" key="k" }
                        <option value="{$k}" {if input('get.userid')==$k}selected {/if}>{$vo}</option>
                        {/foreach}
                    </select>
                </div>
                {/if}

                <div class="col-sm-12 col-lg-1">
                    <select name="category_id" id="category_id" class="form-control">
                        <option value="99999">全部分类</option>
                        {foreach name='categoryList'  item="vo" key="k"}
                        <option value={$k} {if input('get.category_id')==$k} selected{/if}>{$vo}</option>
                        {/foreach}
                    </select>
                </div>

                <!-- 只有工作台下-抖音才能选择模板 -->

                <script src="/public/plugs/datepicker/js/foundation-datepicker.js"></script>
                <script>
                    $(() => {
                        $('#uid').change(() => {
                            window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91' + "&uid=" + $('#uid option:selected').val();
                        });
                        $('#channel').change(() => {
                            window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91' + "&channel=" + $('#channel option:selected').val();
                        });
                        $('#category_id').change(() => {
                            window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91' + "&category_id=" + $('#category_id option:selected').val();
                        });
                        //下拉排序
                        $('#pub_sort').change(() => {
                            var pub_sort = $('#pub_sort option:selected').val();
                            window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91&pub_sort=' + pub_sort;
                        });

                        $('#mb').change(() => {
                            window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91' + "&mb=" + $('#mb option:selected').val();
                        });

                    });
                    $('#startdata').fdatepicker({
                        format: 'yyyy-mm-dd',
                        // pickTime: true
                    });
                    $('#enddata').fdatepicker({
                        format: 'yyyy-mm-dd',
                        // pickTime: true
                    });
                </script>
            </form>
        </div>
    </header>
    <div class="main-box-body clearfix">
        <!-- 搜索相关 -->
        <ul class="navs clearfix" style="margin: 10px 5px;">
            <li><span class="text-muted">频道：</span></li>
            <li><a href="?&book_id={$book_id}&level={$level}&tag_id={$tagId}&channel=99" {if $channel==99}class="active" {/if}>全部</a></li>
            <li><a href="?&book_id={$book_id}&level={$level}&tag_id={$tagId}&channel=1" {if $channel==1}class="active" {/if}>男频</a></li>
            <li><a href="?&book_id={$book_id}&level={$level}&tag_id={$tagId}&channel=2" {if $channel==2}class="active" {/if}>女频</a>
            </li>
        </ul>

        <ul class="navs clearfix" style="margin: 10px 5px;">
            <li><span class="text-muted">标签：</span></li>
            <li>
                <a href="?&book_id={$book_id}&level={$level}&channel={$channel}&tag_id=99999" {if $tagId==99999}class="active" {/if}>全部</a></li>
            {foreach name='tags'  item="vo" key="k"}
            <li>
                <a href="?&book_id={$book_id}&level={$level}&channel={$channel}&tag_id={$k}" data-tagId="{$k}" {if $tagId== $k}class="active"{/if}>{$vo}</a>
            </li>
            {/foreach}
        </ul>

        <div style=" display: flex;align-items: flex-start;margin: 10px 5px;">
            <ul class="navs clearfix bookName" style="height: 21px;">
                <li><span class="text-muted">书名：</span></li>
                <li>
                    <a href='?&tag_id={$tagId}&level={$level}&channel={$channel}&book_id=9999999' {if $book_id==9999999}class="active" {/if}>全部</a></li>
                {foreach bookList as $k => $v}
                <li>
                    <a href="?&tag_id={$tagId}&level={$level}&channel={$channel}&book_id={$k}" data-bookId="{$v}" {if $book_id== $k}class="active"{/if}>{$v}</a>
                </li>
                {/foreach}
            </ul>
            <div class="spread">
                <span style="display: inline;">展开</span>
                <div id="create_book_id">
                    <i class="fa fa-plus"></i> 添加
                </div>
            </div>
        </div>

        <ul class="navs clearfix" style="margin: 10px 5px;">
            <li><span class="text-muted">级别：</span></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=99" {if $level==99}class="active" {/if}>全部</a></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=2" {if $level==2}class="active" {/if}>主图</a></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=3" {if $level==3}class="active" {/if}>二图</a></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=4" {if $level==4}class="active" {/if}>三图</a></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=1" {if $level==1}class="active" {/if}>普通</a></li>
            <li><a href="?&book_id={$book_id}&tag_id={$tagId}&channel={$channel}&level=5" {if $level==5}class="active" {/if}>单推</a></li>
        </ul>
        <div class="table-responsive clearfix">
            <div class="table-responsive clearfix">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th width="3%">
                            <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;">
                        </th>
                        <th width="3%">编号</th>
                        <th width="42%">内容</th>
                        <th width="8%">复制文案</th>
                        <th width="5%">工作台</th>
                        <th width="5%">评分
                            <a href="javascript:;" onclick="score_sort('asc')"><i class="fa fa-sort-amount-asc" aria-hidden="true"></i></a>
                        </th>
                        <script>
                            function score_sort(sort) {
                                window.location.href = 'http://testadmin.ksyuedu.com/admin/material/baidu_1_1.html?platform_ids=1&page=91' + "&score_sort=" + sort;
                            }
                        </script>
                        <th width="15%">点击量/点击率/回款/工号</th>
                        <th width="5%">标签</th>
                        <th width="5%">书名</th>
                        <th width="10%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}
                    <tr><td colspan="10" align="center">暂无数据</td></tr>
                    {/empty}
                    {volist name="list" id="vo"}
                    <tr>
                        <td>
                            <input class="ids row-selected" type="checkbox" name="id[]" value="{$vo.id}">
                        </td>
                        <td>
                            {$vo.id}
                        </td>
                        <td class="toolTip">
                            <div class="example" style="font-size: 17px;  color: #5c5c5c;" title2="">
                                {$vo.content}
                            </div>
                        </td>
                        <td>
                            <div class="copy" onclick="copyContent(`{$vo.content}`, {$vo['id']})">
                                <span class="iconfont icon-copy"></span>
                            复制(<span class="copyNum">{$vo.copy}</span>)
                            </div>
                        </td>
                        <td>
                            <div onclick="follow(this, 236)" class="copy">
                                <span class="fa fa-plus"></span>
                                &nbsp;加入
                                (0)
                            </div>
                        </td>
                        <td>{$vo.score}</td>
                        <td> {$vo.click_volume}/ {$vo.click_rate}% / {$vo.return_money} / {$vo.uname}</td>
                        <td>
                            {foreach $vo.tags as $kk}
                            <span class="label label-success" style="background-color:#a0a4bf;margin-bottom: 3px;display: inline-block;">{$kk}</span>&nbsp;
                            {/foreach}
                        </td>

                        <td>{$vo.book_name}</td>
                        <td>
                            <a href="{:url('del',array('id'=>$vo['id'],'type'=>'twtitle'))}" class="ajax-get confirm"><i class="fa fa-times"></i> 删除</a>
                            <a href="JavaScript:;" onclick="editreferral(this,'create-referral-link-modal','edit')" data-json='{:json_encode($vo)}'>
                                <i class="fa fa-edit"></i> 修改</a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="create-referral-link-modal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <span style="font-size: 20px;"><span id="referralname">添加</span></span>
            </div>
            <div class="modal-body">
                <div data-bind="visible: loading" class="loading-panel" style="display: none;">
                    <i class="fa fa-spin fa-spinner"></i>
                </div>
                <form class="form-horizontal modelform">
                    <style>
                        .form-group {
                            margin-bottom: 10px;
                        }

                        .models input[type=checkbox] {
                            float: left;
                            margin-left: -20px;
                        }

                        .checkbox-inline + .checkbox-inline,
                        .radio-inline + .radio-inline {
                            margin-left: 0;
                        }

                        .required {
                            color: red;
                        }
                    </style>
                    <input type="hidden" name="id" id="createspreadid">

                    <div class="form-group models">
                        <label class="control-label col-sm-2">
                            <span class="required">*</span> 级别</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="level"  value="1"  >
                                <span>普通</span>
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="level"  value="2" >
                                <span>主图</span>
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="level"  value="3">
                                <span>二图</span>
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="level" value="4">
                                <span>三图</span>
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="level" value="5">
                                <span>单推</span>
                            </label>
                        </div>
                    </div>
                    <input type="hidden" name="type" value="1">
                    <div class="form-group models">
                        <label class="control-label col-sm-2">
                            频道</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input type="radio" name="channel" value="1">
                                <span>男频</span>
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="channel" value="2">
                                <span>女频</span>
                            </label>

                        </div>
                    </div>
                    <div class="form-group models">
                        <label class="control-label col-sm-2">
                            分类</label>
                        <div class="col-sm-10">
                            {foreach name='categoryList'  item="vo" key="k"}
                            <label class="radio-inline">
                                <input type="radio" name="category_id" value={$k}>
                                <span>{$vo}</span>
                            </label>
                            {/foreach}
                        </div>
                    </div>
                    <div class="form-group models">
                        <label class="control-label col-sm-2">
                            标签</label>
                        <div class="col-sm-10">
                            {foreach name='tags'  item="vo" key="k"}
                            <label class="radio-inline">
                                <input type="checkbox" name="tag" value={$k}>
                                <span>{$vo}</span>
                            </label>
                            {/foreach}
                        </div>
                    </div>
                    <div class="form-group models">
                        <label class="control-label col-sm-2">
                            书名</label>
                        <div class="col-sm-10">
                            {foreach bookList as $k => $v}
                            <label class="radio-inline">
                                <input type="radio" name="book_id" value={$k}>
                                <span>{$v}</span>
                            </label>
                            {/foreach}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2">点击量</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="score" name="click_volume" value=0 placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2">点击率</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="score" name="click_rate" value=0 placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2">回款</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="score" name="return_money" value=0 placeholder="">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-sm-2">评分</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="score" name="score" value=0 placeholder="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2">文案</label>
                        <div class="col-lg-8">
                            <textarea class="form-control" name="content" id="content" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="form-group" id="batchtxt">
                        <label class="control-label col-sm-2">批量上传</label>
                        <div class="col-lg-8">
                            <div class="picker-box">
                                <div id="picker_ebook" class="picker_button webuploader-container">
                                    <div class="webuploader-pick">
                                        <div>上传文案</div>
                                    </div>
                                    <div id="rt_rt_1ghtc96u61sng1nkg1r19u8m1tns1"
                                         style="position: absolute; inset: 0px auto auto 0px; width: 88px; height: 32px; overflow: hidden;">
                                        <input type="file" name="file" class="webuploader-element-invisible"
                                               multiple="multiple"><label
                                            style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                                    </div>
                                </div>
                                <input type="hidden" name="ebook" id="field_ebook" value="">
                                <div id="fileList_ebook" class="upload-file-list-info">(请上传.txt文件， 1行一个文案)
                                </div>
                            </div>

                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" id="createTwtitle" class="btn btn-primary ">提交</button>
            </div>
        </div>
    </div>
</div>
{include file="adsmaterialbook/_from" /}
{/block}
{block name="script"}
<script src="__PUBLIC__/admin/material/js/jquery-tooltipify.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-editable.min.js"></script>
<script src="__PUBLIC__/plugs/moment/moment.min.js"></script>
<script src="__PUBLIC__/plugs/moment/zh-cn.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.custom.js"></script>
<script type="text/javascript">
        var url;
        $("#createTwtitle").on('click',function(){
            var data = $('.modelform').serializeJson();
            $.ajax({
                type: "POST",
                url: url,
                data:data,
                dataType: "json",
                success: function(data){
                    if(data.code==1){
                        updateAlert(data.msg, 'success');
                        setTimeout(function() {
                            window.location.reload();
                        }, 100);
                    }else{
                        updateAlert("添加，"+data.msg, 'danger');
                    }
                }
            })
        });

        $('#createUrl').on('click', function () {
            url = "{:url('addTwtitle')}"
            var $modal = $('#create-referral-link-modal');
            $modal.on('shown.bs.modal', function () {
                $('#batchtxt').show()
                $('#picker_ebook').html('<div>上传文案</div>')
                $("#picker_ebook").SentUploader({
                    server: "{:url('Upload/Uploadtxt')}",
                    fileNumLimit: 1,
                    uploadEvents: {
                        uploadComplete: function (file) {
                        }
                    },
                    listName: 'fileList_ebook',
                    hiddenName: 'field_ebook',
                    hiddenValType: 2,
                    fileSingleSizeLimit: 50 * 1024 * 1024,
                    closeX: true
                });
            });
            $modal.modal({backdrop: 'static', keyboard: false});
        });


    // 筛选框
    $(() => {
        //频道
        $('#category_id').change(() => {
            search()
        });
        $('#userid').change(() => {
            search()
        });

        function search(){
            let searchUrl = `?category_id=${$('#category_id').val()}&userid=${$('#userid').val()}&startdata=${$('#startdata').val()}&enddata=${$('#enddata').val()}`
            window.location.href= searchUrl
        }

    });
    function editreferral(e,modelName) {
        var jsonStr = $(e).attr('data-json');
        var $modal = $('#'+modelName);
        url = "{:url('editTwtitle')}"
        $modal.on('show.bs.modal', function () {
            $('#batchtxt').hide()
            var json =  eval("(" + jsonStr + ")");
            let keys = Object.keys(json)
            for (var i = 0; i < keys.length; i++){
                if(keys[i]=='content'){
                    $("#content").html(json[keys[i]]);
                }else if(keys[i]=='channel'||keys[i]=='category_id'||keys[i]=='book_id'||keys[i]=='level'){
                    $("input:radio[name="+keys[i]+"][value="+json[keys[i]]+"]").attr("checked",true);
                }else if(keys[i]=='tag'){
                    if(typeof json[keys[i]] == 'object'){
                        multipleInput(json[keys[i]],$(`input:checkbox[name=${keys[i]}]`))
                    }else{
                        multipleInput(json[keys[i]].toString().split(''),$(`input:checkbox[name=${keys[i]}]`))
                    }
                }else{
                    $(`input[name=${keys[i]}]`).val(json[keys[i]])
                }
            }
            $('#picker_ebook').html('<div>上传文案</div>')
            $("#picker_ebook").SentUploader({
                server: "{:url('Upload/Uploadtxt')}",
                fileNumLimit: 1,
                uploadEvents: {
                    uploadComplete: function (file) {
                    }
                },
                listName: 'fileList_ebook',
                hiddenName: 'field_ebook',
                hiddenValType: 2,
                fileSingleSizeLimit: 50 * 1024 * 1024,
                closeX: true
            });
        });
        $modal.modal({backdrop: 'static', keyboard: false});
    };

    //展开功能
    var BN_height;
    if(GetQueryString('book_id')){
        $('.spread span').show()
        $('.bookName').animate({ height: $('.bookName').height()+2+"px" })
        $('.spread span').text('收回')
    }
    if ($('.bookName').height() > 60) {
        BN_height = $('.bookName').height()
        $('.bookName').height('62') 
        $('.spread span').show()
    }else{
        $('.spread span').hide()
    }
    $('.spread span').click(function () {
        let status = $('.spread span').text().trim()
        if (status == '展开') {
            $('.bookName').animate({ height: BN_height+2+"px" })
            $('.spread span').text('收回')
        } else {
            $('.bookName').animate({ height: "62px" })
            $('.spread span').text('展开')
        }
    })
    function multipleInput(arr,e){
        if(arr.length!==0){
            arr.forEach((v,index)=>{
                $(e).each((item,elem)=>{
                    if(v === $(elem).val()){
                        $(elem).attr("checked",true);
                    }
                })
            })
        }
    }
    // 复制
    function copyContent(content, id){
        content = content.toString().replace(/<br\/>/g, `
    `)
        content = content.replace(/<em>|<\/em>/g,'');
        var oInput = document.createElement('textarea');
        oInput.value = content;
        document.body.appendChild(oInput);
        oInput.select();
        document.execCommand("Copy"); 
        oInput.className = 'oInput';
        oInput.style.display='none';
        var url = "{:url('copy')}";
        $.ajax({
            type: "POST",
            url,
            data:{id,type:'twtitle'},
            dataType: "json",
            success: function(data){
                if(data.code==1){
                    layer.msg('复制成功');
                    setTimeout(function(){
                        window.location.reload();
                    }, 500)
                }else{
                    updateAlert("失败，"+data.msg, 'danger');
                }
            }
        })
    }
</script>
{/block}